//--------------------------------------------------- // Purpose: Functions to generate and search arrays // Author: John Gauch //--------------------------------------------------- #include using namespace std; // Function that creates random data void random_data(int array[], int size) { for (int i=0; i array[i]) sorted = false; } return sorted; } // Function that uses reference parameter void is_sorted(int array[], int size, bool &sorted) { // check if array is in sorted order sorted = true; for (int i=1; i array[i]) sorted = false; } } int main() { // Declare and initialize array const int SIZE = 20; int data[SIZE] = {0}; srandom(time(NULL)); sorted_data(data, SIZE); print_data(data, SIZE); // Test the is_sorted function bool sorted = is_sorted(data, SIZE); if (sorted) cout << "the array was sorted\n"; else cout << "the array was NOT sorted\n"; // Get user input int number = 0; cout << "enter a number: "; cin >> number; // Test the search function bool found = false; search(number, data, SIZE, found); if (found) cout << "found the value: " << number << endl; else cout << "didn't find the value: " << number << endl; }